# coding: UTF-8

import urllib
from google.appengine.api import urlfetch
from django.utils import simplejson
import logging

class ReverseGeoCoder:

    def __init__(self, appid, datum='wgs'):
        self.appid = appid
        self.datum = 'wgs'
        self.url = 'http://reverse.search.olp.yahooapis.jp/OpenLocalPlatform/V1/reverseGeoCoder'

    def execute(self, lat, lon):
        url = self.url 
        url +=  '?' + urllib.urlencode({
              'appid'   : self.appid ,
              'datum'   : self.datum,
              'output'  : 'json',
              'lat'     : lat,
              'lon'     : lon,
              })
        logging.info(url)
        result = urlfetch.fetch( url , method=urlfetch.GET)
        return simplejson.loads( result.content )       
 
